<?php

namespace easydis\APSBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class PlagehoraireType extends AbstractType
{
        /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('id', 'hidden')
            ->add('lib', 'text')
            ->add('heuredebut_eng', 'time', array('widget' => 'choice', 
                                    'input' => 'datetime', 
                                    'with_seconds' => false,
                                    'view_timezone' => "Europe/Paris"
                                    ))
            ->add('heurefin_eng', 'time', array('widget' => 'choice', 
                                    'input' => 'datetime', 
                                    'with_seconds' => false,
                                    'view_timezone' => "Europe/Paris"
                                    ))
            ->add('temps', 'text')
            ->add('visibilite', 'checkbox', array('label' => 'Visibilitée :', 'required' => false))
            ->add('ordre', 'text', array('required' => false));
       
        $builder->add('groupe_service', 'entity', array('class' => 'easydisAPSBundle:GroupeService','property' => 'lib', 'multiple' => false,
                        'query_builder' => function($repository){
                        return $repository->createQueryBuilder('gs')
                                ->where('gs.type=2');
                        }));
    }
    
    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'easydis\APSBundle\Entity\Plagehoraire'
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'easydis_apsbundle_plagehoraire';
    }
}
